home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11268 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  35 lines

  1. Path: EU.net!sun4nl!ittpub!ittpub!nntp
  2. Newsgroups: comp.lang.c++
  3. Subject: Re: [Q]Dereference within class - Possible?
  4. Message-ID: <1996Mar13.130156.1804@ittpub>
  5. From: wil@ittpub.nl (Wil Evers)
  6. Date: 13 Mar 96 13:01:56 WET
  7. References: <Do566t.F1H.0.queen@torfree.net>
  8. Distribution: world
  9. Nntp-Posting-Host: lintilla
  10.  
  11. In article <Do566t.F1H.0.queen@torfree.net> bh332@torfree.net (Karim  
  12. Ladha) writes:
  13. > Greetings,
  14. > In normal C style, one can code the following example(C++ compiler);
  15. > int main() {
  16. >   int x   = 1;
  17. >   int &x1 = x;
  18. >   ...
  19. > }
  20. > Is it also possible to use the same syntax within a class without
  21. > intializing the referencer? Any information will be appreciated...
  22.  
  23. A reference is not a pointer. In particular, a reference must always refer  
  24. to some object (there is no such thing as the NULL reference) and it  
  25. cannot be changed to refer to some other object. This is why references  
  26. must be initialized at the point where they come into existence. If you  
  27. need more flexibility, you'll have to use pointers and live with their  
  28. dangers.
  29.  
  30. - Wil
  31.  
  32.